# -*- coding: utf-8 -*- 
# @Title     : ST3字体主题设置
# @Date      : 2014.4.20
# @Author    : aaron(583643865@qq.com)
# @Version   : V1.0


import wx
import GetThemeList
import FileRead

class ThemeDialog(wx.Dialog):
	def __init__(self,path):

		self.installDir=path

		#读取了配置文件
		self.themeFile=FileRead.PreferenceRead(self.installDir+"\\Data\\Packages\\User\\Preferences.sublime-settings")

		#当前主题
		self.currentTheme=self.themeFile.getCurrentTheme()
		#主题列表
		self.themeList=self.convert()


		#界面搭建
		wx.Dialog.__init__(self,None,-1,"Theme",size=(230,332),style=wx.CLOSE_BOX|wx.CAPTION|wx.SYSTEM_MENU)
		panel=wx.Panel(self,-1)
		text=wx.StaticText(panel,-1,"Theme List",(70,10),(150,20))

		self.listbox=wx.ListBox(panel,-1,(20,35),(180,200),self.themeList,wx.LB_SINGLE)
		self.listbox.SetSelection(0)

		#self.okbtn=wx.Button(panel,-1,"Apply",pos=(20,250),size=(75,28))
		self.cancelbtn=wx.Button(panel,-1,"Cancel",pos=(20,250),size=(180,32))

		#绑定事件
		self.Bind(wx.EVT_LISTBOX,self.onSelect,self.listbox)
		# self.Bind(wx.EVT_BUTTON,self.onOk,self.okbtn)		
		self.Bind(wx.EVT_BUTTON,self.onCancel,self.cancelbtn)

	#这个是用户，用方向键选择主题。
	def onSelect(self,event):
		index=self.listbox.GetSelection()
		selectTheme=self.listbox.GetString(index)		
		self.themeFile.setTheme(GetThemeList.GetList(self.installDir).themeList[selectTheme])
		

	#用户点击OK按钮
	# def onOk(self,event):
	# 	index=self.listbox.GetSelection()
	# 	selectTheme=self.listbox.GetString(index)
	# 	self.themeFile.setTheme(self.GetThemeList.GetList(self.installDir).themeList[selectTheme])
	# 	self.Destroy()

	#用户点击取消按钮
	def onCancel(self,event):
		self.themeFile.setTheme(self.currentTheme)
		self.Destroy()

	#将主题的字典文件转化为列表文件，用来初始化ListBox
	def convert(self):
		templist=[]
		dict=GetThemeList.GetList(self.installDir)

		for x in dict.themeList:
			templist.append(x)
		return templist


if __name__ == '__main__':
	theme=GetThemeList.GetList("D:\\program files\\sublime text\\Sublime Text3")
	app=wx.App()
	frame=ThemeDialog("D:\\program files\\sublime text\\Sublime Text3")

	frame.Show(True)
	app.MainLoop()
		
		